<template>
  <div class="players">
    <div class="beautify-scroll">
      <div class="item" v-for="item of playerList" :key="item.id">
        <span class="name ewg-ellipsis" :title="item.username + '#' + item.id">
          <span>玩家</span>：{{ item.username }}
        </span>
        <input
          v-if="wsId !== item.id"
          type="button"
          value="给予"
          @click="handleGive(item.id)"
        />
      </div>
    </div>
  </div>
  <TradeDialog ref="TradeDialog"></TradeDialog>
</template>
<script lang="ts">
import { useStore } from "@/store";
import { computed, defineComponent, ref } from "vue";

const store = useStore();
export default defineComponent({
  name: "OnLinePlayers",
  setup() {
    const TradeDialog = ref();
    const playerList = computed(() => {
      return store.state.onlinePlayers;
    });
    const handleGive = (id: number) => {
      TradeDialog.value.open(id);
    };
    const wsId = computed(() => {
      return store.state.wsId;
    });
    return {
      playerList,
      handleGive,
      TradeDialog,
      wsId
    };
  }
});
</script>
<style lang="scss" scoped>
.players {
  position: fixed;
  right: -240px;
  bottom: 100px;
  width: 240px;
  height: 30%;
  border: 5px solid $--color-blur;
  border-radius: $--border-radius;
  background: $--color-pitwhite;
  box-sizing: border-box;
  padding: 5px;
  transition: right 0.3s linear;
  & > div {
    overflow-y: auto;
    overflow-x: visible;
    width: 100%;
    height: 100%;
  }
  &::after {
    content: "在线玩家列表";
    display: block;
    width: 12px;
    position: absolute;
    left: -30px;
    top: 30px;
    color: $--color-pitwhite;
    background: $--color-blur;
    font-size: 12px;
    padding: 5px 8px;
    border-radius: 10px 0 0 10px;
  }
  &:hover {
    right: 0;
  }
  .item {
    height: 20px;
    margin-bottom: 3px;
    padding-bottom: 5px;
    border-bottom: 1px solid #bebebe;
    &:last-of-type {
      margin-bottom: 0;
      padding-bottom: 0;
      border-bottom: 0;
    }
    .name {
      vertical-align: text-bottom;
      display: inline-block;
      width: 160px;
      margin-right: 10px;
      font-size: 14px;
      color: #666666;
      & > span {
        color: #a9a9a9;
      }
    }
  }
}
</style>
